﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Dict;
using UI;
using Battle;
using Battle.View;
using ProtoBuf.Message;
using Dict.DataModel;
using Room;

namespace Copy
{
    public delegate void Handler();
    public class CopyManager
    {
        static private CopyManager inst;
        static public CopyManager Instance
        {
            get
            {
                if(inst==null)
                {
                    inst = new CopyManager();
                }

                return inst;
            }
        }

        public void CopyToBattleScene(Copy.Handler handler)
        {
            EasyTouchTool.Instance.Hide();

            CSCopyFightStart csStart = new CSCopyFightStart();
            csStart.chapterId = StaticData.currFightChapterId;
            csStart.missionId = StaticData.currFightLevelId;
            csStart.taskId = StaticData.currFightTaskId;
            

            NetAPI.SendHttp(OpDefine.CSCopyFightStart, csStart, (obj, ok) =>
            {
                if (ok)
                {
                    SCCopyFightStart scStart = (SCCopyFightStart)obj.kBody;
                    StaticData.curBattleData.SetData(scStart);
                    handler();
                }
                else
                {
                    Debug.LogError("Enter copy battle error!");
                    var runMap = PageManager.Instance.currentPage as UI.UICopyRunMap;
                    runMap.EndIntoBattleEffect();
                    LoadingPanel.Instance.HideMask(0.5f);

                    BoxManager.CreateReloginBox(LanguageTool.GetTextNoUpdate(1047));
                    //ManagerController.Instance.BackToLogin();
                }
            });
        }

       
    }
}